import modelExtend from 'dva-model-extend'
import { message } from 'antd'
import { routerRedux } from 'dva/router';
import {
    personalDetail
} from 'services/user'
import { pageModel } from './common'
import queryString from 'query-string';

export default modelExtend(pageModel, {
    namespace: 'userCenter',

    state: {

    },

    subscriptions: {
        setup({ dispatch, history }) {
            history.listen((location) => {
                console.log(location)
                if (location.pathname.includes('/chzu/userCenter')){
                    dispatch({
                        type:'personalDetail',
                    })
                }
            })
        },
    },

    effects: {
        *personalDetail({payload},{call,put}){
            const res = yield call(personalDetail);
            console.log(res);
            if(res.code === '200'){
                const userData = res.data;
                yield put({
                    type:'updateState',
                    payload:userData
                })
            }
        }


    },

    reducers: {
        updateState(state,{payload}){
            return {
                ...state,
                userData:payload
            }
        }
    },
})
